package com.amsp.oa.oademo.service.impl;

import com.amsp.oa.oademo.entity.OvertimeApply;
import com.amsp.oa.oademo.mapper.OvertimeApplyMapper;
import com.amsp.oa.oademo.service.OvertimeApplyService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

@Service
public class OvertimeApplyServiceImpl extends ServiceImpl<OvertimeApplyMapper, OvertimeApply>
        implements OvertimeApplyService {

    @Override
    public IPage<OvertimeApply> getPage(Integer current, Integer size, String employeeId, String name,
            String department) {
        Page<OvertimeApply> page = new Page<>(current, size);
        LambdaQueryWrapper<OvertimeApply> wrapper = new LambdaQueryWrapper<>();

        // 添加搜索条件
        if (StringUtils.hasText(employeeId)) {
            wrapper.like(OvertimeApply::getEmployeeId, employeeId);
        }
        if (StringUtils.hasText(name)) {
            wrapper.like(OvertimeApply::getName, name);
        }
        if (StringUtils.hasText(department)) {
            wrapper.like(OvertimeApply::getDepartment, department);
        }

        // 按创建时间倒序排序
        wrapper.orderByDesc(OvertimeApply::getCreateTime);

        return this.page(page, wrapper);
    }
}